<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:text="@string/pregunta_text" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/verdad_button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/falso_button" />
</LinearLayout>
</LinearLayout>
<string name="verdad_button">Verdad</string>
<string name="falso_button">Falso</string>
<string name="correcto_toast">Correcto</string>
<string name="incorrecto_toast">Incorrecto</string>
private lateinit var botonVerdad : Button
private lateinit var botonFalso : Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
botonVerdad = findViewById(R.id.verdad_button)
botonFalso = findViewById(R.id.falso_button)
botonVerdad.setOnClickListener {view : View ->
val muestraMensaje = Toast.makeText(this, R.string.correcto_toast, Toast.LENGTH_SHORT)
muestraMensaje.show()
}
botonFalso.setOnClickListener {view : View ->
val muestraMensaje = Toast.makeText(this, R.string.incorrecto_toast, Toast.LENGTH_SHORT)
muestraMensaje.show()
}
}
makeText(context: Context, resId: Int, duration: Int).
el mensaje de TOAST me debe mostrar en la parte superior de la pantalla.
usar la funcion setGravity de la clase TOAST.